<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<script>

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	function BSkeyDown(e){

		 var ieKey = event.keyCode;

		 if (ieKey==13){
		   if (event.srcElement.id == "searchName"){
			   searchCust(); 
			   event.returnValue=false;
		   } else
			   event.returnValue=false; 
		 } 
	} 
	document.onkeydown = BSkeyDown;
	
	var params = "";

	dataGrid = $('#dataGrid').datagrid({
		url : 'headQCustMgmtJSONAction!listCustTagData',
		queryParams: params,
		fit : true,
		border : false,
		pagination : true,
		pageSize : 15,
		pageList : [ 15, 30],		
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		showFooter:true,
		nowrap : false,
		rownumbers : true,
		sortName : 'status',
		sortOrder : 'asc',
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 1)
				style += 'color:red;';

			return style;
		},
		columns : [ [
 		    {
				field : 'id',
				title : '客户账号',
				width : 70,
				sortable:true,
				order:'asc'
			},{	
				field : 'name',
				title : '客户名字',
				width : 150,
				sortable:true,
				order:'desc'
			},{	
				field : 'tags',
				title : '客户标签',
				width : 170			
			},{			    
				field : 'area',
				title : '客户地区',
				width : 90,
				sortable:true,
				order:'desc'
				
		    }, {
				field : 'phone',
				title : '客户电话',
				width : 90
		    }, {		    	
				field : 'address',
				title : '地址',
				width : 200
		    }, {	
	    	
				field : 'currentAcctBalance',
				title : '当前账目',
				width : 90,
				sortable:true,
				order:'desc'
			}, {
				field : 'comment',
				title : '备注信息',
				width : 90
			}, {
				field : 'status',
				title : '状态',
				width : 50,
				sortable:true,
				order:'desc',
				formatter: function (value, row, index){
					if (row.status == 0 )
						return "正常";
					else if (row.status == 1)
						return "冻结";
				}
			}, {				
				field : 'action',
				title : '更改',
				width : 50,
			formatter : function(value, row, index) {
				var str = '';
				str += $.formatString('<a href="#" onclick="updateCust(\'{0}\');"><img border="0" src="{1}" title="更改客户信息"/></a>', row.id, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/text_1.png');
				return str;
			}
		}]],
		toolbar : '#toolbar',
	});

});

function AddCust(){
	var params = "";

	$.modalDialog.opener_dataGrid = dataGrid;
	
	$.modalDialog({
		title : "添加/更新客户信息",
		width : 540,
		height : 380,
		modal : false,
		draggable:false,
		href : 'headQCustMgmtJSPAction!preEditCust',
		
	});
}
function updateCust(id){
	var params = "formBean.cust.id=" + id;
	$.modalDialog({
		title : "添加/更新客户信息",
		width : 540,
		height : 380,
		modal : false,
		draggable:false,
		href : 'headQCustMgmtJSPAction!preEditCust?' + params,
		
	});
}
function EditCust(){
	var rows = dataGrid.datagrid('getSelections');
	if (rows.length == 0){
		parent.$.messager.alert('错误', '请选中一个客户信息再继续操作', 'error');
		return;
	}
	
	var	id = rows[0].id;

	updateCust(id);
	

}
function downloadCust(){
	document.searchForm.action="headQCustMgmtJSPAction!downloadCustExcelReport";
	document.searchForm.submit();
}
function searchCust(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}
function cleanSearch(){
	$('#searchForm input').val('');
	dataGrid.datagrid('load', {});
}
function refresh(){
	dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
}


/**
 * 批量添加客户标签
 */
function insertCustTags(){

	var rows = dataGrid.datagrid('getSelections');
	var param = "";
	if(rows.length>0){
		for(let index=0;index < rows.length; index++){
			param = param+"formBean.ids=" + rows[index].id+"&"			
		}
		
		var tagId;		
		var count = 0;
		
		if($("#tagLevelOne").combobox('getValue') != null  && $("#tagLevelOne").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelOne").combobox('getValue'); 
		}
		if($("#tagLevelTwo").combobox('getValue') != null && $("#tagLevelTwo").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelTwo").combobox('getValue'); 
		}
		if($("#tagLevelThree").combobox('getValue') != null && $("#tagLevelThree").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelThree").combobox('getValue'); 
		}
		if($("#tagLevelFour").combobox('getValue') != null && $("#tagLevelFour").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelFour").combobox('getValue'); 
		}
		
		if(count == 1){
			var params = param+ "formBean.tagId=" + tagId;			
			$.post("headQCustMgmtJSONAction!saveBatchEntityTags",params, callBack,"json");
		}else if(count == 0){
			$.messager.alert('提示','请选择客户标签客户标签！','warning');
		}else {
			$.messager.alert('提示','不能同时添加多组客户标签,请重新选择！','warning');
		}
		
	}  else {
		$.messager.alert('提示','客户信息为空,请选择要添加的客户！','warning');
	}
	
}

/**
 * 批量删除客户标签
 */
function clearCustTags(){
	var rows = dataGrid.datagrid('getSelections');

	var param = "";
	if(rows.length>0){
		for(let index=0;index < rows.length; index++){
			param = param+"formBean.ids=" + rows[index].id+"&"			
		}
		var tagId;		
		var count = 0;
		
		if($("#tagLevelOne").combobox('getValue') != null  && $("#tagLevelOne").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelOne").combobox('getValue'); 
		}
		if($("#tagLevelTwo").combobox('getValue') != null && $("#tagLevelTwo").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelTwo").combobox('getValue'); 
		}
		if($("#tagLevelThree").combobox('getValue') != null && $("#tagLevelThree").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelThree").combobox('getValue'); 
		}
		if($("#tagLevelFour").combobox('getValue') != null && $("#tagLevelFour").combobox('getValue') != ""){
			count ++;
			tagId = $("#tagLevelFour").combobox('getValue'); 
		}
		
		
		if(count == 1){
			var params = param+ "formBean.tagId=" + tagId   
		    $.post("headQCustMgmtJSONAction!deleteBatchEntityTags",params, callBack,"json");
		}else if(count == 0){
			$.messager.alert('提示','请选择客户标签客户标签！','warning');
		}else {
			$.messager.alert('提示','只能选择一组客户标签！','warning');
		}
		
	} else {
		$.messager.alert('提示','客户信息为空,请选择要修改的客户！','warning');
	}
	
}

/**
 * 回调
 */
function callBack(data){
	$.messager.alert('提示',data.message);
	
}

</script>
</head>
<body>
	<div class="easyui-layout"  data-options="fit : true,border : false">
		<div data-options="region:'north',border:false" style="height: 85px; overflow: hidden;">
			<form id="searchForm" name="searchForm" method="post">
				<table border="0" class="table table-hover table-condensed" style="display: block;">
					<tr>
					<td colspan="10" height="40"><strong>请选择查询条件：</strong></td>
					</tr>
				</table>
				<strong>客户姓名:</strong>
				<input type="text"  style="width:150px" class="easyui-textbox" value=""  data-options="prompt:'请输入客户名称'" name="formBean.cust.name" id="name" placeholder="可以模糊查询客户名字" />
				<strong>一组标签</strong>
				<s:select size="1" cssClass="easyui-combobox"  style="width:150px" data-options="prompt:'请选择第一组标签'" headerKey="" headerValue="" id="tagLevelOne" list="uiBean.tagLevelOne" listKey="id" name="formBean.tagLevelOne" listValue="tagName" />
				<strong>二组标签</strong>
				<s:select size="1" cssClass="easyui-combobox"  style="width:150px" data-options="prompt:'请选择第二组标签'" headerKey="" headerValue="" id="tagLevelTwo" list="uiBean.tagLevelTwo" listKey="id" name="formBean.tagLevelTwo" listValue="tagName" />
				<strong>三组标签</strong>
				<s:select size="1" cssClass="easyui-combobox"  style="width:150px" data-options="prompt:'请选择第三组标签'" headerKey="" headerValue="" id="tagLevelThree" list="uiBean.tagLevelThree" listKey="id" name="formBean.tagLevelThree" listValue="tagName" />
				<strong>四组标签</strong>
				<s:select size="1" cssClass="easyui-combobox"  style="width:150px" data-options="prompt:'请选择第四组标签'" headerKey="" headerValue="" id="tagLevelFour" list="uiBean.tagLevelFour" listKey="id" name="formBean.tagLevelFour" listValue="tagName" />
			</form>
		</div>
		<div data-options="region:'center',border:false">
				<table id="dataGrid">			       
		        </table>
	
			<div id="toolbar" style="display: none;">
			         <a onclick="searchCust();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索客户</a>
			         <a onclick="cleanSearch();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true">清空查询</a>
		             <a onclick="AddCust();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">添加</a>
                     <a onclick="EditCust();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">更改</a>
                     <a onclick="downloadCust();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">下载客户信息</a>
                     <a onclick="refresh();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">刷新</a>
                     <s:if test="(#session.LOGIN_USER.containFunction('headQCustMgmtJSONAction!saveBatchEntityTags')) ">
					<a onclick="insertCustTags();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-add',plain:true">批量添加客户标签</a> 
					</s:if>
					<s:if test="(#session.LOGIN_USER.containFunction('headQCustMgmtJSONAction!deleteBatchEntityTags')) ">
					 <a
					onclick="clearCustTags();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-no',plain:true">批量清空客户标签</a> 
					</s:if>
	        </div>
		</div>
	</div>
</body>
</html>